//
//  CategoryViewController.m
//  EasyBuy
//
//  Created by Zhu Xiangjun on 10/7/12.
//  Copyright (c) 2012 shen donghao. All rights reserved.
//

#import "CategoryViewController.h"
#import "CategoryTableView.h"

@interface CategoryViewController (){
    UISearchBar *searchBar;
    CategoryTableView *categoryTableView;
}

@end

@implementation CategoryViewController

-(void)dealloc{
    [super dealloc];
    [searchBar release];
    [categoryTableView release];
}

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {

    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    
    self.navigationItem.title = @"类目导航";

    UISearchBar *_searchBar = [[UISearchBar alloc] initWithFrame:CGRectMake(0, 0, 320, 45)];
    _searchBar.backgroundColor = [UIColor colorWithRed:16.0f/255.0f green:126.0f/255.0f blue:213.0f/255.0f alpha:1.0f];
    NSMutableArray* unneededViews = [NSMutableArray array];
    for (UIView* aView in [_searchBar subviews]) {
        if (! [NSStringFromClass([aView class]) isEqualToString:@"UISearchBarTextField"]) {
            [unneededViews addObject:aView];
        }
    }
    [unneededViews makeObjectsPerformSelector:@selector(removeFromSuperview)];
    searchBar = _searchBar;
    [self.view addSubview: searchBar];
    [_searchBar release];
    
    CategoryTableView *_categoryTableView = [[CategoryTableView alloc]initWithFrame:CGRectMake(0, searchBar.frame.origin.y+searchBar.frame.size.height, 320, 300)];
    _categoryTableView.delegate   = _categoryTableView;
    _categoryTableView.dataSource = _categoryTableView;
    categoryTableView = _categoryTableView;
    [self.view addSubview:categoryTableView];
    [_categoryTableView release];
    
}

- (void)viewDidUnload
{
    [super viewDidUnload];
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

@end
